package cms.mager.service.impl;

import cms.common.CodeMsg;
import cms.common.PageData;
import cms.common.Result;
import cms.mager.dao.CustomerDao;
import cms.mager.domain.Customer;
import cms.mager.service.CustomerService;

import java.util.Map;

/**
 * 功能:
 * Author: yuhui
 * Date: 2021/4/9 21:35
 */
public class CustomerServiceImpl implements CustomerService {
    CustomerDao c_Dao = new CustomerDao();

    /*1、分页查询*/
    @Override
    public Result getpage(PageData pd, Map param) {
        Object[] objarr = {(pd.getPage()-1)*pd.getPageSize(),pd.getPageSize()};
        PageData<Customer> customerPageData = c_Dao.pageCustomer(pd, param, objarr);

        return new Result(customerPageData);
    }

    /*2、添加客户*/
    @Override
    public Result addData(Object[] param) {
        boolean b = c_Dao.addCustomer(param);
        Result rt = null;
        if(b){
            rt = new Result();
        }else{
            rt = new Result(CodeMsg.ERROR_CUSTOMER_FIND);
        }
        return rt;
    }

    /*3、更新客户信息*//*[就更手机号吧]*/
    @Override
    public Result updateData(Map<String,String> param,String[] pName) {
        boolean b = c_Dao.updateInfo(param,pName);
        Result rt = null;
        if(b){
            rt = new Result();
        }else{
            rt = new Result(CodeMsg.ERROR_CUSTOMER_UPDATE);
        }
        return rt;
    }

    /*4、删除客户信息*/
    @Override
    public Result delData(int id) {
        boolean b = c_Dao.delCustormer(id);
        Result rt = null;
        if(b){
            rt = new Result();
        }else{
            rt = new Result(CodeMsg.ERROR_CUSTOMER_UPDATE);
        }
        return rt;
    }

    @Override
    public Result setUserToCu(String[] cusIds, String uid) {
        Result rt = null;
        boolean b = c_Dao.updateUser(cusIds, uid);
        if(b){
            rt = new Result();
        }else{
            rt = new Result(CodeMsg.ERROR_CUSTOMER_UPDATE);
        }
        return rt;
    }

}
